﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Outer.Master"
    CodeBehind="Login2.aspx.vb" Inherits="LecturerAppointmentSystem.Login2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="fb-root">
    </div>
    <script type="text/javascript">
        window.fbAsyncInit = function () {
            FB.init({ appId: '<%= LecturerAppointmentSystem.callback.FaceBookAppKey %>', status: true, cookie: true, xfbml: true, oauth: true });
            /* All the events registered */
            FB.Event.subscribe('auth.login', function (response) {
                // do something with response
                login();
            });
            FB.Event.subscribe('auth.logout', function (response) {
                // do something with response
                logout();
            });

            FB.getLoginStatus(function (response) {
                showSession(response);
                //FB.Event.subscribe('auth.sessionChange', showSession);
            });

            FB.Event.subscribe('auth.sessionChange', function (response) {
            if (response.authResponse) {
                getAccessToken();
                }
            });

            //            FB.getLoginStatus(function (response) {
            //                if (response.session) {
            //                    // logged in and connected user, someone you know
            //                    login();
            //                }
            //            });
            
        };
        (function () {
            var e = document.createElement('script');
            e.type = 'text/javascript';
            e.src = document.location.protocol +
                    '//connect.facebook.net/en_US/all.js';
            e.async = true;
            document.getElementById('fb-root').appendChild(e);
        } ());

        function login() {
            FB.api('/me', function (response) {
                document.getElementById('login').style.display = "block";
                document.getElementById('login').innerHTML = response.name + " succsessfully logged in!";
            });
        }
        function logout() {
            document.getElementById('login').style.display = "none";
        }
        

        function fqlQuery() {
            FB.api('/me', function (response) {
                var query = FB.Data.query('select name, hometown_location, sex, pic_square from user where uid={0}', response.id);
                query.wait(function (rows) {

                    document.getElementById('name').innerHTML =
                         'Your name: ' + rows[0].name + "<br />" +
                         '<img src="' + rows[0].pic_square + '" alt="" />' + "<br />";
                });
            });
        }

        function getAccessToken() {
            FB.getLoginStatus(function (response) {
                var html = 'Not Connected';
                if (response.authResponse) {
                    html = response.authResponse.accessToken;
                }
                document.getElementById('access-token').innerHTML = html;
                __doPostBack('callPostBack', html);
                FB.Event.subscribe('auth.sessionChange', showSession);
            });
//            var showSession = function (response) {
//                var html = 'Not Connected';
//                if (response.authResponse) {
//                    html = response.authResponse.accessToken;
//                }
//                document.getElementById('access-token').innerHTML = html;
//                __doPostBack('callPostBack', html);
//            };
        }        
        </script>
 
        <h3>New Graph api & Javascript Base FBConnect Tutorial | Thinkdiff.net</h3>
        <p><fb:login-button autologoutlink="true" perms="email,offline_access" onclick="getAccessToken"></fb:login-button></p>
        <p><asp:Button ID="fbLoginButton" runat="server" Text="Login"/></p>
 
        <p>
            <a href="#" onclick="fqlQuery(); return false;">FQL Query Example</a>
        </p>
 
        <textarea id="status" cols="50" rows="5">Write your status here and click 'Status Set Using Legacy Api Call'</textarea>
        <br />
        <a href="#" onclick="setStatus(); return false;">Status Set Using Legacy Api Call</a>
 
        <br /><br /><br />
        <div id="login" style ="display:none"></div>
        <div id="name"></div>
        <div id="access-token"></div>
        <asp:TextBox ID="txtJSValue" runat="server"></asp:TextBox>
        <asp:Button ID="btnJSValue" Text="Click to retreive Javascript Variable" runat="server" />

</asp:Content>
